import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { MenuService } from './menu.service';
import { CreateMenuDto } from './dto/create-menu.dto';
import { UpdateMenuDto } from './dto/update-menu.dto';
import { Result } from 'src/utils/Result';
import { ApiOperation, ApiParam, ApiProduces, ApiTags } from '@nestjs/swagger';

@ApiTags('菜单模块')
@Controller('menu')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}
  @ApiOperation({ description: '获取所有菜单列表' })
  @Get('list')
  async findMenuWithTree() {
    const result = await this.menuService.findMenuWithTree();
    return Result.success(result);
  }
  @Get('tree_list')
  async findMenuWithSelectTree() {
    const result = await this.menuService.findMenuWithSelectTree();
    return Result.success(result);
  }
  @Post('create')
  @ApiOperation({ description: '新增菜单' })
  @ApiParam({ name: 'menu_name', required: true, description: '菜单名称' })
  @ApiParam({ name: 'parent_id', required: true, description: '菜单上级id' })
  @ApiParam({ name: 'order_num', required: true, description: '显示顺序' })
  @ApiParam({ name: 'path', required: true, description: '路径地址' })
  @ApiParam({ name: 'component', required: false, description: '组件名称' })
  @ApiParam({ name: 'query', required: false, description: '路径参数' })
  @ApiParam({ name: 'is_frame', required: false, description: '是否是外链 0是 1否' })
  @ApiParam({ name: 'is_cache', required: false, description: '是否缓存 0是 1否' })
  @ApiParam({ name: 'menu_type', required: false, description: '菜单类型 M目录 C菜单 F按钮' })
  @ApiParam({ name: 'visible', required: false, description: '显示状态 0显示 1隐藏' })
  @ApiParam({ name: 'status', required: false, description: '菜单状态 0正常 1禁用' })
  @ApiParam({ name: 'perms', required: false, description: '权限标识' })
  @ApiParam({ name: 'icon', required: false, description: '菜单图标' })
  @ApiParam({ name: 'remark', required: false, description: '备注' })
  async create(@Body() createMenuDto: CreateMenuDto) {
    const result = await this.menuService.create(createMenuDto);
    return Result.success(result)
  }

  @Get('query:id')
  findOne(@Param('id') id: string) {
    return this.menuService.findOne(+id);
  }

  @Patch('update:id')
  update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
    const result = this.menuService.update(+id, updateMenuDto);
    return Result.success(result)
  }

  @Delete('del:id')
  remove(@Param('id') id: string) {
    return this.menuService.remove(+id);
  }
}
